<?php
function get_total_category(){
    global $wpdb;  
    
    $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM ".$wpdb->prefix."terms t
                                             INNER JOIN ".$wpdb->prefix."term_taxonomy tx ON tx.term_id = t.term_id 
                                             WHERE tx.taxonomy = 'bs_category'" ) );
    
    return $count > 0 ? $count: 0 ;
    
}


function get_total_watting_approve($type='', $where = ''){
    global $wpdb;   
    
    switch($type)  {
        case 'business_listing':
            if($where!='') $where = ' AND '.$where;
            $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM ".$wpdb->prefix."posts WHERE type='businesslisting". $where ) );
        break;        
        default:
            if($where!='') $where = ' WHERE '.$where;
            $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM ".$wpdb->prefix.$type. $where ) );
        break;
    }
    
    return $count > 0 ? $count: 0 ;
    
}
function company_total ($approve=''){
    global $wpdb;
    $sql = "SELECT COUNT(*) FROM ".$wpdb->prefix."users u 
            INNER JOIN ".$wpdb->prefix."company wpc ON  wpc.user_id = u.ID". (($approve=='')?'':" WHERE wpc.approved=". $approve);
	$count = $wpdb->get_var($wpdb->prepare($sql));
    
    return $count > 0 ? $count: 0 ;
}
function accm_Site_Manager(){ 
    
    global $wpdb, $user_ID, $msg;        
  
    ?>           

    <div class="wrap" id="accm_Site_Manager">        
        <h2>Business Partners - Administration Panel</h2>
        <div id="tab-menu">
            <ul>    
                <li class="<?php print ($_GET['tabmenu']==''? 'selected':'');?>"><a href="?page=<?php print $_GET['page'];?>">Home</a></li>                
                <li class="<?php print ($_GET['tabmenu']=='company'? 'selected':'');?>"><a href="?page=<?php print $_GET['page'];?>&tabmenu=company">Company</a></li>
                <li class="<?php print ($_GET['tabmenu']=='business'? 'selected':'');?>"><a href="?page=<?php print $_GET['page'];?>&tabmenu=business">Business Listing</a></li>
                <li class="<?php print ($_GET['tabmenu']=='coupons'? 'selected':'');?>"><a href="?page=<?php print $_GET['page'];?>&tabmenu=coupons">Coupons</a></li>               
            </ul>
        </div> 
        <div id="Site_Manager_Content">
            <div class="tab_content">
               <?php if( $_GET['tabmenu']=='') { ?>
                    <h3>Summary</h3>
    
                    Total Categories: <strong><?php print get_total_category();?></strong> - <a href="?page=accm_Category_Management">View</a>
                         <br />
                    Total Company: <strong><?php print company_total();?></strong> - <a href="?page=<?php print $_GET['page'];?>&tabmenu=company">View</a>
                        | <strong><?php print company_total('0');?></strong> <a href="/wp-admin/admin.php?page=accm&tabmenu=company">Waiting for Approval</a> 
                    <br />
                    Total Business Listing: <strong><?php print get_total_watting_approve('business_listing');?></strong> - <a href="?page=<?php print $_GET['page'];?>&tabmenu=business">View</a>
                     | <strong><?php print get_total_watting_approve('business_listing'," status != 'publish' ");?></strong> <a href="/wp-admin/admin.php?page=accm&tabmenu=business">Waiting for Approval</a>
                    <br />
                    Total Coupon(s): <strong><?php print get_total_watting_approve('coupons');?></strong> - <a href="?page=<?php print $_GET['page'];?>&tabmenu=coupons">View</a>
                     | <strong><?php print get_total_watting_approve('coupons',' approved=0');?></strong> <a href="/wp-admin/admin.php?page=accm&tabmenu=business">Waiting for Approval</a>
                    <br />
                <?php } else {
                    if(in_array($_GET['tabmenu'],array('cuisine','pricerange','hotelregion','neighborhood')))
                        include('terms_data.php');
                    else
                        include($_GET['tabmenu'].'.php');
                } ?>
            </div>           
        </div>
    </div>
<?php } ?>